#ifndef  __WIRELESSWIRELESSPROTOCOL_H__
#define  __WIRELESSWIRELESSPROTOCOL_H__

#define  FRAME_DATA_LTH_VENDORID   (2)
#define  FRAME_DATA_LTH_ESEALID    (4)
#define  FRAME_DATA_LTH_READERID   (2)

#define  PHY_USE_CC2500                     (0x01)
#define  PHY_USE_CC1100                     (0x02)

#define  WIRELESSPROTOCOL_CMD_NULL                        (0x00)
#define  WIRELESSPROTOCOL_CMD_LF_WAKEUP                   (0x01)

#define  WIRELESSPROTOCOL_P2P_CMD_SLEEP                   (0x10)
#define  WIRELESSPROTOCOL_P2P_CMD_READ_PARA               (0x11)
#define  WIRELESSPROTOCOL_P2P_CMD_READ_RTC                (0x12)
#define  WIRELESSPROTOCOL_P2P_CMD_AUTHORIZE               (0x13)
#define  WIRELESSPROTOCOL_P2P_CMD_HANDLE_ESEAL            (0x14)
#define  WIRELESSPROTOCOL_P2P_CMD_READ_EVENT_RECORD       (0x15)
#define  WIRELESSPROTOCOL_P2P_CMD_READ_EVENT_NUM          (0x16)
#define  WIRELESSPROTOCOL_P2P_CMD_PORT_INOUT              (0x17)
#define  WIRELESSPROTOCOL_P2P_CMD_READ_STATUS             (0x18)
#define  WIRELESSPROTOCOL_P2P_CMD_PERIOD_SEND_ONOFF       (0x19)

#define  WIRELESSPROTOCOL_BROADCAST_CMD_COLLECT           (0x20)

#define  CMD_HANDLE_ESEAL_OPTION_SEAL            (0x01)
#define  CMD_HANDLE_ESEAL_OPTION_OPEN            (0x02)
#define  CMD_HANDLE_ESEAL_OPTION_CLOSE           (0x03)
#define  CMD_HANDLE_ESEAL_OPTION_UNSEAL          (0x04)
#define  CMD_HANDLE_ESEAL_OPTION_CHECKRTC        (0x05)

#define  CMD_READ_PARA_OPTION_ESEALID                           (0x01)
#define  CMD_READ_PARA_OPTION_VENDORID                          (0x02)
#define  CMD_READ_PARA_OPTION_MODEID                            (0x03)
#define  CMD_READ_PARA_OPTION_FW_VERSION                        (0x04)
#define  CMD_READ_PARA_OPTION_PWIRELESSPROTOCOL_VERSION         (0x05)
#define  CMD_READ_PARA_OPTION_EVENTS_NUM                        (0x06)
#define  CMD_READ_PARA_OPTION_COLLECT_OVERTIME                  (0x07)
#define  CMD_READ_PARA_OPTION_P2P_OVERTIME                      (0x08)

#define  CMD_COLLECT_RULE_ALL          (0x00)
#define  CMD_COLLECT_RULE_SEALED       (0x02)
#define  CMD_COLLECT_RULE_OPENED       (0x04)

#define  PACKET_TANS_OK                             (0x01)
#define  PACKET_TANS_ERR_CRC                        (0x02)
#define  PACKET_TANS_ERR_READER_MISSMATCH           (0x03)
#define  PACKET_TANS_ERR_WAIT_PARSE                 (0x04)

#define  FRAME_PARSE_OK             (0x01)
#define  FRAME_PARSE_ERR            (0x02)
#define  FRAME_PARSE_DATA_EXIST     (0x03)

typedef struct 
{
  INT8U   ProtocolID;
  INT8U   PacketOption;
  INT8U   VendorID[FRAME_DATA_LTH_VENDORID];
  INT8U   eSealID[FRAME_DATA_LTH_ESEALID];
  INT8U   ReaderID[FRAME_DATA_LTH_READERID];
  INT8U   Command;
  INT16U  MinCmdLastTime;
  INT16U  MaxCmdLastTime;
  INT8U   ParameterLth;
  INT8U*  pParameter;
}WIRELESSPROTOCOL_P2P_DOWN_FRAME;

typedef struct 
{
  INT8U   ProtocolID;
  INT16U  eSealStatus;
  INT8U   ReaderID[FRAME_DATA_LTH_READERID];
  INT8U   VendorID[FRAME_DATA_LTH_VENDORID];
  INT8U   eSealID[FRAME_DATA_LTH_ESEALID];
  INT8U   Command;
  INT8U   DataLth;
  INT8U*  pData;
}WIRELESSPROTOCOL_P2P_UP_FRAME;

typedef struct 
{
  INT8U   ProtocolID;
  INT8U   PacketOption;
  INT8U   ReaderID[2];
  INT8U   Command;
  INT8U   ParameterLth;
  INT8U*  pParameter;
}WIRELESSPROTOCOL_BROADCAST_DOWN_FRAME;


INT8U eSeal_SendCmd_Sleep(INT8U* pVendorID,INT8U* peSealID ,INT8U* err);

INT8U eSeal_SendCmd_Authorize(INT8U* pVendorID , INT8U* peSealID , INT8U* pAuthorizeCode,INT8U* err);

INT8U eSeal_SendCmd_ReadRTC(INT8U* pVendorID,INT8U* peSealID,INT8U* err);

INT8U eSeal_SendCmd_HandleeSeal(INT8U* pVendorID , INT8U* peSealID , INT8U* pAuthorizeCode , INT8U OptionType , INT8U* err);

INT8U eSeal_SendCmd_ReadPara(INT8U* pVendorID , INT8U* peSealID , INT8U OptionType , INT8U* err);

INT8U eSeal_SendCmd_ReadEventRecord(INT8U* pVendorID , INT8U* peSealID , INT16U RecordNo , INT8U* err);

INT8U eSeal_SendCmd_ReadEventNum(INT8U* pVendorID , INT8U* peSealID , INT8U* err);

INT8U eSeal_SendCmd_PortInOut(INT8U* pVendorID , INT8U* peSealID , INT8U InOut,INT8U* err);

INT8U eSeal_SendCmd_ReadStatus(INT8U* pVendorID , INT8U* peSealID ,INT8U* err);

INT8U eSeal_SendCmd_PeriodSend(INT8U* pVendorID , INT8U* peSealID ,INT8U bOnOff, INT8U Period , INT8U* err);

INT8U eSeal_SendCmd_Collect(INT8U CollectRule , INT8U* err);

INT8U eSeal_SendCmd_LowFrequencyWakeUp(INT8U Channel , INT8U* err);

INT8U  Packet2Frame(WIRELESSPROTOCOL_P2P_UP_FRAME* pRecvFrame , PHY_FRAME* pRecvPacket);
INT8U  ParseP2PPacket(WIRELESSPROTOCOL_P2P_UP_FRAME* pRecvFrame , INT8U* perr);

extern INT8U   CurrentReaderID[];
#endif

